<?php

namespace App\Model\Mongodb;

use Hyperf\Di\Annotation\Inject;
use Hyperf\Task\Annotation\Task;
use App\Lib\Mongo\MongoDb as MongoDbBase;

class MongoDb
{
    /**
     * @Inject()
     * @var MongoDbBase
     */
    protected $client;

    protected $db_name = '';

    /**
     * 查询数据
     */
    public function showList(array $filter = [], array $options = []){
        var_dump($this->db_name);
        return $this->client->fetchAll($this->db_name,$filter,$options);
    }


    /**
     * @Task
     */
    public function query(string $table, array $filter = [], array $options = [])
    {
        return $this->client->fetchAll($table, $filter, $options);
    }

    public function fetchAll(string  $table, array  $filter = [], array  $options = []){
        return $this->client->fetchAll($this->db_name,$filter,$options);
    }

    /**
     * @Task
     */
    public function first(string $table, array $filter = [], array $options = [])
    {
        return $this->client->fetchAll($table, $filter, $options)[0];
    }

    /**
     * @Task
     */
    public function page(string $table, array $filter = [], int $pageSize, int $page, array $options = [])
    {
        return $this->client->fetchPagination($table, $pageSize, $page, $filter, $options);
    }

    /**
     * @Task
     */
    public function insert(string $table, array $document)
    {
        return $this->client->insert($table,$document);
    }

    /**
     * @Task
     */
    public function insertGetId(string $table, array $document)
    {
        return $this->client->insertGetId($table,$document);
    }

    /**
     * @Task
     */
    public function insertAll(string $table, array $document)
    {
        return $this->client->insertAll($table,$document);
    }



    /**
     * @Task
     */
    public function update(string $table, array $filter = [], array $document)
    {
        return $this->client->updateRow($table, $filter, $document);
    }

    /**
     * @Task
     */
    public function delete(string $table, array $filter = [], $all = false)
    {
        return $this->client->delete($table, $filter, $all);
    }

    /**
     * @Task
     */
    public function execute(string $table, $pipeline)
    {
        return $this->client->command($table, $pipeline);
    }

    /**
     * @Task
     */
    public function count(string $table, $filter = [])
    {
        return $this->client->count($table, $filter);
    }


}